<?php

namespace FortendBundle\Controller;

use BaseBundle\Controller\BaseController;
use Symfony\Component\HttpFoundation\Request;

class HomePageController extends BaseController
{
    /**
     * 首页
     *
     * @param Request $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function homePageAction(Request $request)
    {
        $token = $request->getSession()->get('token');
        $user_info = $token != null ? $this->getUserInfo($token) : array();
        $data = array(
            'user_info'=> $user_info,
        );
        return $this->render('@Fortend/homePage.html.twig', array('data'=> $data));
    }

    /**
     * 登录
     */
    public function loginAction()
    {
        $data = array(
            'user_info'=> array(),
        );
        return $this->render('@Fortend/login.html.twig', array('data'=> $data));
    }

    /**
     * 注册
     */
    public function registerAction()
    {
        $data = array(
            'user_info'=> array(),
        );
        return $this->render('@Fortend/register.html.twig', array('data'=> $data));
    }

    /**
     * 发帖
     *
     * @param Request $request
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function postIssueAction(Request $request)
    {
        $class = $request->get('class');
        $token = $request->getSession()->get('token');
        $user_info = $token != null ? $this->getUserInfo($token) : array();

        $conn = $this->get('database_connection');
        $article_type = $conn->fetchAll("SELECT * FROM article_classify");

        $data = array(
            'user_info' => $user_info,
            'article_type' => $article_type
        );
        if ($token == null) {
            return $this->render('@Fortend/login.html.twig', array('data'=> $data));
        } else {
            return $this->render('@Fortend/postOpera.html.twig', array('data'=> $data));
        }
    }
}
